package Client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;

import org.feiteira.network.copy.SeriClient;

import com.googlecode.cqengine.IndexedCollection;

import NET.NetPlayer;

public class Client implements Runnable {
   public static void main(String[] args) {
      new Client();
   }

   SeriClient sc;

   public Client() {
      try {
         sc = new SeriClient("localhost", 4445);
         sc.setEventListner(new ClientEventHandler());
         new Thread(sc).start();
         new Thread(this).start();
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

   @Override
   public void run() {
      BufferedReader stdIn = new BufferedReader(
            new InputStreamReader(System.in));
      String fromUser = null;
      while (sc.isOpen()) {
         fromUser = null;
         System.out.print("Enter the next line:");
         while (fromUser == null) {
            try {
               fromUser = stdIn.readLine();
            } catch (IOException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
            }
            if (fromUser != null) {
               System.out.println("Client: " + fromUser);
               try {
                  sc.send(fromUser);
               } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
               }
            }
         }
      }
   }
}
